package com.kugua.zfms.rank.pojo;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer;
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.time.LocalDateTime;
import java.time.ZoneOffset;

/**
 * <p>TODO</p>
 * <p>
 * <PRE>
 * <BR>    修改记录
 * <BR>-----------------------------------------------
 * <BR>    修改日期         修改人          修改内容
 * </PRE>
 *
 * @author cuiyh9
 * @version 1.0
 * @Date Created in 2019年01月07日 14:09
 * @since 1.0
 */
public class RankScore {



    private static final LocalDateTime BENCHMARK_DATETIME = LocalDateTime.of(2019,1,1,1,1,1);


    private static final int EPOCH_BIT = 30;

    private static final int LIKE_BIT = 30;

    private static final int TOP_LEFT_BIT = LIKE_BIT + EPOCH_BIT;



    public static long calculateScore(RankObject rankObject) {
        long top = 0L;
        if (rankObject.isTop()) {
            top = 1;
        }
        return  (top << TOP_LEFT_BIT)| (rankObject.getLikeNum() << EPOCH_BIT) | calSeconds(rankObject);
    }

    private static long calSeconds(RankObject rankObject) {
        long epochSecond = rankObject.getCreateDate().toEpochSecond(ZoneOffset.of("+8")) - BENCHMARK_DATETIME.toEpochSecond(ZoneOffset.of("+8"));
        return epochSecond;
    }


}
